package Dao.DateImpl;

import Dao.TeacherDao;
import Model.Teacher;
import Controller.TeacherUI;

/**
 * 数据访问处理层
 */
public class TeacherDaoImpl implements TeacherDao {


    @Override
    public void showTeacherDao(Teacher[] teacher, int len) {
        for (int i = 0; i < len; i++) {
            System.out.println("工号\t姓名\t年龄\t性别\t科目");
            System.out.println(teacher[i].getId() + "\t" + teacher[i].getName() + "\t" + teacher[i].getAge() + "\t" + teacher[i].getSex() + "\t" + teacher[i].getSubject());
        }
    }

    @Override
    public void addTeacherDao(Teacher[] teacher, Teacher people) {

        teacher[TeacherUI.num++] = people;
    }

    @Override
    public boolean delTeacherDao(Teacher[] teacher, String uid, int num) {
        int j = 0;
        boolean flag = false;
        for (int i = 0; i < num; i++) {
            if (teacher[i].getId() == Integer.valueOf(uid)) {
                j = i;
                flag = true;
                break;
            }
        }
        if (flag) {
            for (int i = j; i < num - 1; i++) {
                teacher[i] = teacher[i + 1];
            }
            return flag;
        }
        return flag;
    }

    @Override
    public Integer updateTeacherDao(Teacher[] teacher, String uid, int num) {
        int j = 0;
        for (int i = 0; i < num; i++) {
            if (teacher[i].getId() == Integer.valueOf(uid)) {
                j = i;
               return j;
            }
        }
        return null;
    }
}
